<!-- 调整价格模态 -->
<script type="text/html" id="offer_html">
    <div style="padding:0 10px;">
        <div class="layui-form adjust-price-html" id='offer'lay-filter="offer">
            <table class="layui-table" style="text-align: center">
                <colgroup>
                    <col width="5%">
                    <col width="20%">
                    <col width="10%">
                    <col width="10%">
                    <col width="10%">
                    <col width="10%">
                    <col width="10%">
                    <col width="10%">
                    <col width="10%">
                    <col width="10%">
                </colgroup>
                <thead>
                <tr>
                    <th style="text-align: center">ID</th>
                    <th style="text-align: center">商品规格</th>
                    <th style="text-align: center">供应商</th>
                    <th style="text-align: center">联系人</th>
                    <th style="text-align: center">手机号</th>
                    <th style="text-align: center">省份</th>
                    <th style="text-align: center">城市</th>
                    <th style="text-align: center">区域</th>
                    <th style="text-align: center">报价</th>
                    <th style="text-align: center">库存</th>
                    <th style="text-align: center">操作</th>
                </tr>
                </thead>
                <tbody>
                    {{# if (d.list.length){ }}
                        {{#  layui.each(d.list, function(index, item){ }}
                            <tr>
                                <td>{{ item.id }}</td>
                                <td>{{ item.sku_name }}</td>
                                <td>{{ item.offer_name }}</td>
                                <td>{{ item.offer_person }}</td>
                                <td>{{ item.offer_mobile }}</td>
                                <td>{{ item.province_name || '无' }}</td>
                                <td>{{ item.city_name || '无' }}</td>
                                <td>{{ item.district_name || '无' }}</td>
                                <td>{{ item.price }}</td>
                                <td>{{ item.stock }}</td>
                                <td><a href="javascript:;" class="layui-btn" data-order_goods_id="{{ item.order_goods_id }}" data-offer_id="{{ item.id }}" onclick="select_offer(this);">立即下单</a></td>
                            </tr>
                        {{#  }); }}
                    {{# }else{ }}
                        <tr>
                            <td colspan="11">暂无供应商报价</td>
                        </tr>
                    {{# } }}
                </tbody>
            </table>
            <button class="layui-btn"  lay-submit id="submit" lay-filter="submit" style="display:none;">提交</button>
        </div>
    </div>
</script>
<script>
    var form;
    /**
     * 供应商列表
     */
    function orderOffer(order_goods_id) {
        console.log(order_goods_id);
        $.ajax({
            type: "post",
            url: ns.url("shop/order/getOrderOffer"),
            async: true,
            dataType: 'json',
            data: {
                "order_goods_id": order_goods_id,
            },
            success: function (res) {
                if(res.code === 0){
                    //获取模板
                    var getTpl = $("#offer_html").html();
                    var data = res.data;
                    //渲染模板
                    laytpl(getTpl).render(data, function(html) {
                        layer.open({
                            type: 1,
                            shadeClose: true,
                            shade: 0.3,
                            offset: 'auto',
                            scrollbar: true,
                            fixed: false,
                            title: "供应商选择",
                            area: ['1100px', 'auto'],
                            content:  html,
                            cancel: function(){},
                        });
                        form.render();
                    });
                }
            }
        });
    }

    function select_offer(obj){
        var offer_id = $(obj).data('offer_id');
        var order_goods_id = $(obj).data('order_goods_id');
        $.ajax({
            url: ns.url("shop/order/select_offer"),
            type: "POST",
            dataType: "JSON",
            async: false,
            data: {offer_id: offer_id, order_goods_id: order_goods_id},
            success: function (res) {
                layer.msg(res.message);
				setTimeout(function(){
					location.reload();
				},1500);
            }
        });
    }
</script>